<?php
/*
 * 老人入院表接口
 */
class Apiv1_InhospitalController extends Ctrl_Apiatk{
    public function indexAction(){
        $p = $_REQUEST;
        $pSid = empty($p['sid'])?Tool_Fnc::ajaxMsg('老人ID不能为空'):Tool_Fnc::safe_string($p['sid']);

        $tSMO = new SeniorModel;
        $tNIMO = new NationinfoModel;
        $tSIMO = new SexinfoModel;
        $tEIMO = new EducationlevelsinfoModel;
        $tFMMO = new FamilymembersModel;
        $tBIMO = new BodystatusinfoModel;
        $tRIMO = new ReligioninfoModel;
        $tSCMO = new ScanningModel;
        $tDIMO = new DepartmentinfoModel;

        //基本信息
        $tSql = 'select s.name name,ni.introduce nation,s.birth_date birth_date,si.introduce sex,s.married_status married_status,s.critcode critcode,s.age age,ri.introduce religion,ei.introduce education_levels,s.permanent_residence permanent_residence,s.old_company old_company,old_address old_address,s.temper_hobby temper_hobby,s.allergies allergies,s.medical_orders medical_orders,bi.introduce body_status,s.physical_examination physical_examination,s.life life,s.diet diet,s.sleep sleep,s.goods goods,di.introduce department from '.$tSMO->table.' s left join '.$tNIMO->table.' ni on s.nation = ni.num left join '.$tSIMO->table.' si on s.sex = si.num left join '.$tEIMO->table.' ei on s.education_levels = ei.num left join '.$tFMMO->table.' fm on fm.sid = s.id left join '.$tBIMO->table.' bi on s.body_status = bi.num left join '.$tRIMO->table.' ri on ri.num = s.religion left join '.$tDIMO->table.' di on s.department = di.num where fm.is_client = 1 and s.id = '.$pSid;
        $tSDatas = $tSMO->query($tSql);
        //委托人信息
        $tFMData = $tFMMO->field('name wt_name,sex wt_sex,relation wt_relation,phone wt_phone,address wt_address,critcode wt_critcode')->where('sid = '.$pSid.' and is_client = 1')->fRow();
        //家属信息
        $tFMjsData = $tFMMO->field('name js_name,sex js_sex,relation js_relation,address js_address,critcode js_critcode')->where('sid = '.$pSid.' and is_client = 2')->fList();
        //扫描件
        $tImgUrl = Yaf_Registry::get('config')->web->url->img;
        $tSCDatas = $tSCMO->field('id,concat(\''.$tImgUrl.'\',imgurl) imgurl')->where('sid = '.$pSid)->fList();


        $tDatas = array(array());
        $tDatas = array_merge($tSDatas[0],$tFMData,array('jiashu' => $tFMjsData,'saomiaojian' => $tSCDatas));
        

        Tool_Fnc::ajaxMsg('',1,$tDatas);

    }
}
?>
